import React, { Component } from 'react'
import './index.css'

export default class Footer extends Component {
    handleAllTodo = (event) => {
        this.props.checkAllTodo(event.target.checked);
    }

    render() {
        const { todos } = this.props;
        // 计算已完成的个数
        const doneCount = todos.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0);
        // 计算总数
        const total = todos.length;
        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" checked={doneCount === total && total !== 0 ? true : false} onChange={this.handleAllTodo}/>
                </label>
                <span>
                    <span>已完成{doneCount}</span> / 全部{total}
                </span>
                <button onClick={this.props.clearAllDone} className="btn btn-danger">清除已完成任务</button>
            </div>
        )
    }
}
